﻿@using Smartstore.Web.Rendering.Menus
@using Smartstore.Collections
@using Smartstore.Core.Content.Menus
@using Microsoft.AspNetCore.Mvc.ViewFeatures

@model MenuModel

@{
    var root = Model.Root;
    if (root == null)
    {
        return;
    }

    var selectedNode = Model.SelectedNode;
}

    @foreach (var node in root.Children)
    {
        await CreateMenuItem1(node, selectedNode);
    }

@{
    async Task CreateMenuItem1(TreeNode<MenuItem> node, TreeNode<MenuItem> curNode)
    {
        var itemState = node.GetNodePathState(Model.Path);
        var item = node.Value;
        var itemText = node.GetItemText(T);
        var itemUrl = item.GenerateUrl(this.ViewContext);
        var cssClass = "cate_root_list_item hydrated";

        if ((itemState & NodePathState.Expanded) == NodePathState.Expanded)
        {
            cssClass += " cate_root_list_item_cur";
        }
        if ((itemState & NodePathState.Selected) == NodePathState.Selected)
        {
            cssClass += " cate_root_list_item_cur";
        }
        <a href="@itemUrl">
            <taro-view-core class="@cssClass">
                @itemText
            </taro-view-core>
        </a>
    }
}